/**
 * @param {number[]} differences
 * @param {number} lower
 * @param {number} upper
 * @return {number}
 */
 var numberOfArrays = function(differences, lower, upper) {
  let ans = 0
  let diff = differences[0]
  let min = diff, max = diff
  for(let i = 1; i<differences.length; i++){
    diff += differences[i]
    min = Math.min(min, diff)
    max = Math.max(max, diff)
  }
  const check = (x) => {
    let left = x + min, right = x + max
    if(left < lower) return false
    if(right > upper) return false  
    return true
  }
  for(let i = lower; i<=upper; i++){
    if(check(i)) ans++
  }
  return ans
};